package com.kepler.social.web.controller;

import com.beust.jcommander.internal.Lists;
import com.kepler.social.common.Time;
import com.kepler.social.common.constants.BusinessState;
import com.kepler.social.common.constants.Enums;
import com.kepler.social.common.constants.TipsConst;
import com.kepler.social.common.vo.Dict;
import com.kepler.social.domain.support.sms.SmsBo;
import com.kepler.social.domain.user.account.consts.CommonConst;
import com.kepler.social.web.common.HttpResult;
import com.kepler.social.web.controller.assembler.DictAssembler;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/common")
@Slf4j
public class CommonController {

    @Resource
    private SmsBo smsBo;

    /**
     * 手机验证码
     *
     * @param mobilePhoneNumber
     * @return
     */
    @RequestMapping(value = "/sms-captcha/send")
    public HttpResult smsCaptchaSend(Integer countryCallingCode, Long mobilePhoneNumber) {
        Time timeout = new Time(CommonConst.expireTimeCaptcha, TimeUnit.SECONDS);
        smsBo.sendMobilePhoneCaptcha(countryCallingCode, mobilePhoneNumber, timeout, null);
        return new HttpResult(BusinessState.OK.code, TipsConst.mobile_phone_captcha_sent);
    }

    /**
     * 数据字典
     *
     * @return
     */
    @RequestMapping(value = "/dict")
    public HttpResult<List> dict() {
        return HttpResult.success(
                Lists.newArrayList(
                        new Dict("gender", Enums.DataTypeEnum.Int.type, DictAssembler.toGenderDictItems())));
    }

}
